import Vue from "vue"
import { getUser } from '@/utils/auth'
/**权限指令：可以控制页面上任何一个元素**/
Vue.directive('has', {
    bind: function (el, binding) {
        if (!Vue.prototype.$_has(binding.value)) {
            if (!el.parentNode) {
                el.style.display = 'none'
            } else {
                el.parentNode.removeChild(el)
            }
        }
    }
});

//权限检查方法
Vue.prototype.$_has = function (value) {
    let isExist = true;
    if (value != undefined) {
        let normalPermissions = getUser("normalPermissions");//受到控制的普通权限
        let permissions = getUser("permissions");//当前用户的权限
        if (normalPermissions == null || permissions == null) {
            return false;
        }
        let normalPermissionsArr = normalPermissions.split(';');
        let permissionsArr = permissions.split(';');
       
        if (normalPermissionsArr.includes(value) && !(permissionsArr.includes(value))) {
            isExist = false;
        }
    }
    return isExist;
};